/*********************************************************************************
  *FileName:  nsuc16xx_tmr.h
  *Version:   V1.0
  *Date:      2023-10-15
**********************************************************************************/

#ifndef  __nsuc16xx_tmr_H__
#define  __nsuc16xx_tmr_H__

/***************************************Includes***********************************/
#include "nsuc16x0.h"



/***************************************Macros***********************************/
#define TIM_OCMode_Freeze									((uint8_t)0x00)
#define TIM_OCMode_Active									((uint8_t)0x01)
#define TIM_OCMode_Inactive								((uint8_t)0x02)
#define TIM_OCMode_Toggle									((uint8_t)0x03)
#define TIM_OCMode_OutActive							((uint8_t)0x04)
#define TIM_OCMode_OutInactive						((uint8_t)0x05)
#define TIM_OCMode_PWM1										((uint8_t)0x06)
#define TIM_OCMode_PWM2										((uint8_t)0x07)


#define TIM_OCPolarity_High								((uint8_t)0x00)
#define TIM_OCPolarity_Low								((uint8_t)0x01)

#define TIM_OutputState_Disable           ((uint8_t)0x00)
#define TIM_OutputState_Enable            ((uint8_t)0x01)

#define TMR_IT_Update											((uint8_t)0x01)		/* Timer Counter Update Event Interrupt */
#define TMR_IT_OC													((uint8_t)0x02)		/* Timer Compare Interrupt */
#define TMR_IT_IC													((uint8_t)0x04)		/* Timer Capture Interrupt */
#define TMR_IT_ICO												((uint8_t)0x08)		/* Timer OverCapture Interrupt */
#define TMR_IT_OV													((uint8_t)0x10)		/* Timer Couter Interrupt */

/***************************************Variables***********************************/
typedef struct
{
  uint16_t TMR_Prescaler;         /*!< Specifies the prescaler value used to divide the TMR clock.
                                       This parameter can be a number between 0x0000 and 0xFFFF */
  FunctionalState TMR_UpdateInterrupt;
  FunctionalState TMR_FinishedInterrupt;
  FunctionalState TMR_AutoReload;
  uint16_t TMR_StartCounter;      
  uint16_t TMR_EndCounter; 
} TMR_TimeBaseInitTypeDef; 

typedef struct
{
  uint16_t TMR_OCMode;   
	FunctionalState TMR_CompareInterrupt;  
	FunctionalState TMR_ComparePreload; 
  uint16_t TMR_OutputState;   
  uint16_t TMR_Pulse;        
  uint16_t TMR_OCPolarity; 
	FunctionalState TMR_CompareOut; 
} TMR_OCInitTypeDef;
/***************************************Functions***********************************/
void TMR_TimeBaseInit(TIMER_TypeDef *TMRx, TMR_TimeBaseInitTypeDef *TMR_TimeBaseInitStruct);
void TMR_OCInit(TIMER_TypeDef *TMRx, TMR_OCInitTypeDef *TMR_OCInitStruct);
void TMR_SetCompare(TIMER_TypeDef *TMRx, uint16_t Compare);
void TMR_SetStartCounter(TIMER_TypeDef *TMRx, uint16_t StartCounter);
void TMR_SetEndCounter(TIMER_TypeDef *TMRx, uint16_t EndCounter);
void TMR_Cmd(TIMER_TypeDef *TMRx, FunctionalState NewState);
uint32_t TMR_GetCounter(TIMER_TypeDef *TMRx);
ITStatus TMR_GetITStatus(TIMER_TypeDef *TMRx, uint8_t TMR_IT);
void TMR_ClearITPendingBit(TIMER_TypeDef *TMRx, uint8_t TMR_IT);

#endif
/* [] END OF nsuc16xx_tmr.h */
